package grex.genes;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2003</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */
import grex.BNFException;
import grex.ErrorManager;
import grex.Prediction;
import grex.PredictionContainer;

public class ConVar extends Gene implements ITerminal {

    private static final int NROFCILDREN = 0;
    private int varNr = -1;
    private int count=0;
    public ConVar() throws BNFException {
        super(NROFCILDREN);
    }

    public synchronized void execute(Gene parent, PredictionContainer data, int mode) throws GeneException {
        this.parent = parent;
        if(mode==Gene.TRAIN_MODE){
            count=data.values().size();
        }
        if (varNr==-1) {            
            varNr = environment.getRandomContiousColumnIndex();
        }
        for (Prediction p : data.values()) {
            p.setPrediction(p.getInstance()[varNr]);
            p.setLeaf(this);
            p.setProb(new Double(0));
        }
    }

    public void setVarNr(int varNr) {
        this.varNr = varNr;
    }

    public int getVarNr() {
        return varNr;
    }

    public Object clone() {
        ConVar newVariable;
        try {
            newVariable = new ConVar();
            newVariable.setVarNr(varNr);
            newVariable.setOptions(ops);
            newVariable.setEnvironment(environment);
            newVariable.setParent(parent);
        } catch (grex.BNFException e) {
            ErrorManager.getInstance().reportError(e);
            return null;
        }
        return newVariable;
    }

    public String toString() {
        try {
            if (varNr == -1) {
                varNr = environment.getRandomContiousColumnIndex();
            }
            return environment.getVariableNames()[varNr];
        } catch (GeneException ex) {
            ErrorManager.getInstance().reportError(ex);
        }
        return environment.getVariableNames()[varNr];
    }

    public double getProb() {
        this.getType();
        return 0;
    }

    public double getLowProb() {
        return 0;
    }

    public int getCount() {
        return count;
    }
}
